package lancs.mobilemedia.core.ui.controller.commands;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;

import lancs.mobilemedia.core.ui.controller.AbstractController;
import lancs.mobilemedia.core.ui.controller.ControllerCommand;
import lancs.mobilemedia.lib.exceptions.PersistenceMechanismException;

public class ConfirmDeleteAlbum implements ControllerCommand {

	public boolean execute(AbstractController controller) {
		try {
			controller.getModel().deletePhotoAlbum(controller.getCurrentStoreName());
		} catch (PersistenceMechanismException e) {
			Alert alert = new Alert("Error", "The mobile database can not delete this photo album", null,
					AlertType.ERROR);
			Display.getDisplay(controller.getMidlet()).setCurrent(alert, Display.getDisplay(controller.getMidlet()).getCurrent());
		}
		GoToPreviousScreen previousScreen = new GoToPreviousScreen();
		return previousScreen.execute(controller);
	}

}
